import { TParamsMap } from '../type';

export const COMMAND_PREFIX = 'tt';

/**
 * 判断是否内置命令调用
 */
export function isBuildInCommand(command: string) {
    return !!command.match(`^${COMMAND_PREFIX}`);
}

/**
 * 命令参数解析
 */
export function getParamsMap(params: string[]): TParamsMap {
    const paramsMap = params.reduce((acc: TParamsMap, cur: string) => {
        const [k, v] = cur.split('=');
        acc[k] = v;
        return acc;
    }, {});
    return paramsMap;
}

/**
 * 解决 NPM 命令在不同平台下的命令方式
 */
export function fixSpawnNpmCommand() {
    return /^win/.test(process.platform) ? 'npm.cmd' : 'npm';
}
